/*
 * IPDXMLConfigFileParameters.java
 *
 * Created on 29 de Março de 2010, 18:26
 *
 */

package intopo.game.impl.ipd;

import intopo.evogame.partnerselection.config.ParsingException;
import intopo.game.DescriptionGUI;
import intopo.game.gui.AbstractGameEditorComponent;
import intopo.game.gui.AbstractStrategyEditorComponent;
import intopo.game.gui.AbstractGlobalParametersComponent;
import java.io.PrintStream;

import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author <a href="mailto:plsm@ua.pt">Pedro Lopes da Silva Mariano</a>
 *
 * @version 1.0 29 de Março de 2010
 */
final public class IteratedPrisonerDilemmaDescriptionTextGUI
	extends intopo.game.AbstractDescriptionText<IteratedPrisonerDilemmaGame, IteratedPrisonerDilemmaStrategy>
	implements DescriptionGUI<IteratedPrisonerDilemmaGame, IteratedPrisonerDilemmaStrategy>
{
	final private static IteratedPrisonerDilemmaDescriptionTextGUI instance = new IteratedPrisonerDilemmaDescriptionTextGUI ();

	/**
	 * Return a map that associates tag names to game constructors. The text file should only have a single tag whose name is a key of the returned map.
	 */
	static Map<String, Constructor<? extends IteratedPrisonerDilemmaGame>> gameConstructors ()
	{
		Map<String, Constructor<? extends IteratedPrisonerDilemmaGame>> result;
		Constructor<IteratedPrisonerDilemmaGame> cg;
		result = new HashMap<String, Constructor<? extends IteratedPrisonerDilemmaGame>> ();
		try {
			Class<IteratedPrisonerDilemmaGame> c = IteratedPrisonerDilemmaGame.class;
			cg = c.getConstructor (Scanner.class);
			result.put (IteratedPrisonerDilemmaGame.CONSTRUCTOR_TAG, cg);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class IteratedPrisonerDilemmaGame does not have a constructor with parameter type java.util.Scanner");
			System.exit (1);
			return null;
		}
		return result;
	}
	/**
	 * Return a map that associates tag names to strategy constructors.
	 */
	static private Map<String, Constructor<? extends IteratedPrisonerDilemmaStrategy>> strategyConstructors ()
	{
		Map<String, Constructor<? extends IteratedPrisonerDilemmaStrategy>> result;
		Constructor<? extends IteratedPrisonerDilemmaStrategy> cp;
		result = new HashMap<String, Constructor<? extends IteratedPrisonerDilemmaStrategy>> ();
		try {
			Class<IteratedPrisonerDilemmaProbabilisticStrategy> c = IteratedPrisonerDilemmaProbabilisticStrategy.class;
			cp = c.getConstructor (Scanner.class);
			result.put (IteratedPrisonerDilemmaProbabilisticStrategy.CONSTRUCTOR_TAG, cp);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class IteratedPrisonerDilemmaProbabilisticPlayer does not have a constructor with parameter type java.util.Scanner");
			System.exit (1);
			return null;
		}
		return result;
	}

	public static IteratedPrisonerDilemmaDescriptionTextGUI getInstance ()
	{
		return instance;
	}

	/**
	 * Creates a new instance of IPDXMLConfigFileParameters
	 */
	public IteratedPrisonerDilemmaDescriptionTextGUI ()
	{
		super (gameConstructors (), strategyConstructors (), new intopo.game.impl.ipd.FoldIPDStrategy ());
	}

	@Override
	public String getBinDescription (Class<? extends IteratedPrisonerDilemmaStrategy> c, int bin)
	{
		return IteratedPrisonerDilemmaProbabilisticStrategy.getBinDescription (bin);
	}


	public void readGlobalParameters (Scanner scanner)
		throws ParsingException
	{
		IteratedPrisonerDilemmaProbabilisticStrategy.Parameters.read (scanner);
	}
	@Override
	public void writeGlobalParameters (PrintStream ps)
	{
		IteratedPrisonerDilemmaProbabilisticStrategy.Parameters.write (ps);
	}

	@Override
	public AbstractGameEditorComponent<IteratedPrisonerDilemmaGame, IteratedPrisonerDilemmaStrategy> getGameEditorComponent ()
	{
		return new IteratedPrisonerDilemmaGameComponent ();
	}

	@Override
	public AbstractStrategyEditorComponent<IteratedPrisonerDilemmaStrategy> getStrategyEditorComponent ()
	{
		return new IteratedPrisonerDilemmaStrategyComponent ();
	}

	@Override
	public AbstractGlobalParametersComponent getGlobalParametersEditorComponent ()
	{
		return new IteratedPrisonerDilemmaGlobalParameters ();
	}

}
